package com.shop.technicalservice.dao.shop.impl;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.shop.technicalservice.dao.shop.ShopinfoDao;
import com.shop.technicalservice.model.shop.Shopinfo;

/**
 * A data access object (DAO) providing persistence and search support for
 * Shopinfo entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see org.rjb.pojo.ShopinfoDto
 * @author MyEclipse Persistence Tools
 */

public class ShopinfoDaoImpl extends HibernateDaoSupport implements ShopinfoDao{
	private static final Log log = LogFactory.getLog(ShopinfoDaoImpl.class);
	// property constants
	public static final String NAME = "name";
	public static final String PRICE = "price";
	public static final String NUM = "num";
	public static final String IMGPATH = "imgpath";

	protected void initDao() {
		// do nothing
	}

	public Shopinfo save(Shopinfo transientInstance)  throws Exception{
		log.debug("saving Shopinfo instance");
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		return transientInstance;
	}

	public void delete(Shopinfo persistentInstance)  throws Exception{
		log.debug("deleting Shopinfo instance");
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
	}

	public Shopinfo findById(java.lang.Integer id)  throws Exception{
		log.debug("getting Shopinfo instance with id: " + id);
			Shopinfo instance = (Shopinfo) getHibernateTemplate().get(
					"org.rjb.Shopinfo", id);
			return instance;
	}

	public List findByExample(Shopinfo instance)  throws Exception{
		log.debug("finding Shopinfo instance by example");
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
	}

	public List findByProperty(String propertyName, Object value)  throws Exception{
		log.debug("finding Shopinfo instance with property: " + propertyName
				+ ", value: " + value);
			String queryString = "from Shopinfo as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
	}

	public List findByName(Object name)  throws Exception{
		return findByProperty(NAME, name);
	}

	public List findByPrice(Object price)  throws Exception{
		return findByProperty(PRICE, price);
	}

	public List findByNum(Object num)  throws Exception{
		return findByProperty(NUM, num);
	}

	public List findByImgpath(Object imgpath)  throws Exception{
		return findByProperty(IMGPATH, imgpath);
	}

	public List findAll()  throws Exception{
		log.debug("finding all Shopinfo instances");
			String queryString = "from Shopinfo";
			return getHibernateTemplate().find(queryString);
	}

	public Shopinfo merge(Shopinfo detachedInstance)  throws Exception{
		log.debug("merging Shopinfo instance");
			Shopinfo result = (Shopinfo) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
	}

	public void attachDirty(Shopinfo instance)  throws Exception{
		log.debug("attaching dirty Shopinfo instance");
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
	}

	public void attachClean(Shopinfo instance)  throws Exception{
		log.debug("attaching clean Shopinfo instance");
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
	}

	public static ShopinfoDaoImpl getFromApplicationContext(ApplicationContext ctx) {
		return (ShopinfoDaoImpl) ctx.getBean("ShopinfoDAO");
	}
}